<?php
/**
 * @ClassName: OrderLogic
 * @Description: 订单相关逻辑
 * @author: wyaohu
 * @Date: 2025-07-23 16:43
 * @Version: V1.0.0
 */

namespace app\meituan\logic;

class OrderLogic extends BasicLogic
{
    /**
     * 发单前预览
     * @param $params
     * @return bool|string
     */
    public function preCreateByStore($params)
    {
        $res = $this->curlRequest('/order/preCreateByShop', $params);
        return $res;
    }

    /**
     * 发单
     * @param $params
     * @return bool|string
     */
    public function createByStore($params)
    {
        $res = $this->curlRequest('/order/createByShop', $params);
        return $res;
    }

    /**
     * 查询订单状态
     * @param $delivery_id [配送活动标识]
     * @param $mt_peisong_id [美团配送内部订单id ]
     * @return bool|string
     */
    public function queryOrderStatus($delivery_id, $mt_peisong_id)
    {
        $params = [
            'delivery_id' => $delivery_id,
            'mt_peisong_id' => $mt_peisong_id,
        ];
        $res = $this->curlRequest('/order/status/query', $params);
        return $res;
    }

    /**
     * 获取骑手位置
     * @param $mt_peisong_id [美团配送内部订单id ]
     * @param $delivery_id [配送活动标识]
     * @param string $type
     * @return bool|string
     */
    public function getRiderLocation($mt_peisong_id, $delivery_id, string $type = '')
    {
        if ($type == 'h5') {
            $params = [
                'mt_peisong_id' => $mt_peisong_id,
            ];
            $res = $this->curlRequest('/order/rider/location/h5url', $params);
        } else {
            $params = [
                'delivery_id' => $delivery_id,
                'mt_peisong_id' => $mt_peisong_id,
            ];
            $res = $this->curlRequest('/order/rider/location', $params);
        }
        return $res;
    }

    /**
     * 取消订单
     * @param $params
     * @return bool|string
     */
    public function cancelOrder($params)
    {
        $res = $this->curlRequest('/order/delete', $params);
        return $res;
    }

    /**
     * 取餐码信息下发
     * @param $mt_peisong_id [美团配送内部订单id ]
     * @param $infos [取餐码业务详情信息]
     * @return bool|string
     */
    public function sendMealCodeByPkgId($mt_peisong_id, $infos)
    {
        $params = [
            'mt_peisong_id' => $mt_peisong_id,
            'infos' => $infos,
        ];
        $res = $this->curlRequest('/mealCode/saveMealCodeByPkgId', $params);
        return $res;
    }

    /**
     * 为骑手增加小费
     * @param $params
     * @return bool|string
     */
    public function addTip($params)
    {
        $res = $this->curlRequest('/order/addTip', $params);
        return $res;
    }

    /**
     * 评价骑手服务
     * @param $params
     * @return bool|string
     */
    public function evaluateRider($params)
    {
        $res = $this->curlRequest('/order/evaluate', $params);
        return $res;
    }

    /**
     * 发起餐损申请
     * @param $params
     * @return bool|string
     */
    public function compensationApply($params)
    {
        $res = $this->curlRequest('/compensation/apply', $params);
        return $res;
    }

    /**
     * 发起餐损申诉
     * @param $params
     * @return bool|string
     */
    public function compensationAppeal($params)
    {
        $res = $this->curlRequest('/compensation/appeal', $params);
        return $res;
    }

    /**
     * 查询餐损审核记录
     * @param $mt_peisong_id [美团配送内部订单id ]
     * @return bool|string
     */
    public function queryCompensation($mt_peisong_id)
    {
        $params = [
            'mt_peisong_id' => $mt_peisong_id,
        ];
        $res = $this->curlRequest('/compensation/detail', $params);
        return $res;
    }

}